package com.xbang.attendance.web.action.system.userinfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.demo2do.lighturl.annotation.Action;
import com.xbang.attendance.entity.department.Department;
import com.xbang.attendance.entity.userinfo.Userinfo;
import com.xbang.attendance.service.SystemService;
import com.xbang.core.page.Result;
import com.xbang.core.struts.support.SearchActionSupport;

public class userinfo extends SearchActionSupport {

	private SystemService systemService;
	private Userinfo user;
	
	public Userinfo getUser() {
		return user;
	}

	public void setUser(Userinfo user) {
		this.user = user;
	}

	private List<Userinfo> userinfos = new ArrayList<Userinfo>();

	public List<Userinfo> getUserinfos() {
		return userinfos;
	}

	public void setUserinfos(List<Userinfo> userinfos) {
		this.userinfos = userinfos;
	}

	public void setSystemService(SystemService systemService) {
		this.systemService = systemService;
	}

	@Override
	public void resetCustomerSearchCriteria() {
		// TODO Auto-generated method stub

	}
	private List mapDepartmentlist=new ArrayList();
	
	/*public Map getMapDepartment() {
		return mapDepartment;
	}

	public void setMapDepartment(Map mapDepartment) {
		this.mapDepartment = mapDepartment;
	}
*/
	public List getMapDepartmentlist() {
		return mapDepartmentlist;
	}

	public void setMapDepartmentlist(List mapDepartmentlist) {
		this.mapDepartmentlist = mapDepartmentlist;
	}

	@Action("/system/userinfo/list")
	public String list() throws Exception {
		String hqlSentence = "FROM Userinfo userinfo WHERE 1 = 1";
		Result result = systemService.searchByPage(hqlSentence,
				searchComponent, page);
		userinfos = result.getItems();
		for(int i=0;i<userinfos.size();i++){
			String j = "0";
			userinfos.get(i).getDepartment();
		 //	String name = 	String.valueOf( =null? map.get("department").toString():"";
			int deid= -1;
			
			
				try {
					Map mapDepartment=new HashMap();
					if(userinfos.get(i).getDepartment()==null||"".equals(userinfos.get(i).getDepartment())){
						mapDepartment.put("department", null);
					}else{
						deid	=Integer.valueOf(userinfos.get(i).getDepartment());
						Department dp=(Department) systemService.getObject(Department.class, deid);
						mapDepartment.put("department", dp.getDepartname());
					}
					
					Userinfo userinfo=new Userinfo();
					userinfo=userinfos.get(i);
					mapDepartment.put("uinfo", userinfo);
					mapDepartmentlist.add(mapDepartment);
				} catch (Exception e) {
					e.printStackTrace();
				}
			
		}
		
		page = result.getPage();
		return "index";
	}
}
